﻿#include"test.h"
#include"XQHttpServer.h"
#include"XQSslServer.h"
#include<QApplication>
#include<QDebug>
#include<QDir>
void httpServer()
{
    auto http = new XQHttpServer;
    QObject::connect(qApp, &QApplication::aboutToQuit, http, &QObject::deleteLater);//设置内存释放

    using Debug = Http::Debug;
    XQHttpServer& server=*http;
    server.setDebugModels(Debug::error | Debug::Run | Debug::Connection | Debug::Disconnect | Debug::HeadRequest);
    server.setTimeoutConnection(5_s);
    server.setModel(NetworkType::Tcp);
    auto tcp = server.tcp();
    tcp->setLocalCertificate("./certificate/www.727370630.top_public.crt");
    tcp->setPrivateKey("./certificate/www.727370630.top.key");
    tcp->setProtocol(Http::Protocol::https);
    server.setServerName_local("127.0.0.1");
    server.setPort(6666);




    //server.addSlotFunc("test", [&](const QVariantList& list)->QVariantList
    //    {
    //        //qDebug() <<"接收到数据"<< list;
    //        server.sendSignals("server", { "server-Send",1 });
    //        return { 999999999999,6666666 };
    //    });
    //QObject::connect(&server, &XQHttpServer::signalsRequest, [](const QString& name, const QVariantList& data) {
    //    qDebug() << "signals 客户端" << name << data;
    //    });

    server.run();
    //server.setReplyFunc([](QTcpSocket* socket, XQHttpHeader* header) 
    //    {
    //        // 获取已连接主机的 IP 地址
    //        QHostAddress ipAddress = socket->peerAddress();
    //        QString ip = ipAddress.toString(); // 转换为字符串形式

    //        // 获取已连接主机的端口号
    //        quint16 port = socket->peerPort();
    //        qDebug() << ip + ":" << port << "连接上服务器";
    //        return  QString("ip:%1:%2 我收到了你的信息").arg(ip).arg(port).toUtf8();
    //    });
    //开启线程池
    server.setThreadPool_run(true);
}